package com.huabo.system.controller;

import java.math.BigDecimal;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hbfk.util.JsonBean;
import com.hbfk.util.ResponseFormat;
import com.huabo.system.service.TblStaffService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/user")
@Slf4j
@Api(value="StaffController",tags={"用户信息接口"})
public class StaffController {

	@Resource
	private TblStaffService tblStaffService;
	
	@RequestMapping(value = "/getUserInfoEntity", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
	@ApiOperation(value = "根据token获取当前登录用户信息")
	public JsonBean getUserInfoEntity(HttpServletRequest request,@ApiParam(name = "token", value = "登录用户token", required = true)@RequestHeader(value="token",required=true) String token){
		 try {
			return this.tblStaffService.findUserInfoByToken(token);
		} catch (Exception e) {
			log.error("获取用户信息失败："+e.getMessage());
			return ResponseFormat.retParam(0,60001,e.getMessage());
		}
	}
	
	
	@RequestMapping(value = "/modifyUserPassWord", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "当前用户修改密码")
	@ApiParam(name="token",value="登录用户token",required=true)
	public JsonBean modifyUserPassWord(HttpServletRequest request,@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			 @ApiParam(name = "staffId", value = "用户主键", required = true) @RequestParam(value = "staffId", required = true) Integer staffId,
			 @ApiParam(name = "oldPassWord", value = "原密码", required = true) @RequestParam(value = "oldPassWord", required = true) String oldPassWord,
			 @ApiParam(name = "newPassWord", value = "新密码", required = true) @RequestParam(value = "newPassWord", required = true) String newPassWord,
			 @ApiParam(name = "twoPassWord", value = "第二次新密码", required = true) @RequestParam(value = "twoPassWord", required = true) String twoPassWord){
		 try {
			return this.tblStaffService.modifyUserPassWord(token,staffId,oldPassWord,newPassWord,twoPassWord);
		} catch (Exception e) {
			log.error("获取用户信息失败："+e.getMessage());
			return ResponseFormat.retParam(0,60001,e.getMessage());
		}
	}
	
}
